<?php
function decode($conn) {
	$header = fread($conn,8);
	$data = unpack("Ntype/Nlen",$header);

    extract($data);
	if($type == 0xFE) {
		$size = $len;
	}
	$data = fread($conn, $len);
	return $data;
}

function encode($data) {
	$header =pack("NN",0XFE,strlen($data));
	$header.=$data;
	return $header;
}